Skip to content

fix(cli): os knowledge rebuild and status give the right answer behind a load balancer - #37578

Draft
objectstack-fleet[bot] wants to merge 4 commits into
mainfrom
claude/issue-37466-knowledge-cli-lb
Draft

objectstack-fleet[bot] wants to merge 4 commits into
mainfrom
claude/issue-37466-knowledge-cli-lb

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Bill · project thread

Fixes #37466

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:多节点部署的运维用命令行重建知识源时,进度查询打到别的节点不再直接报失败,而是改看所有节点一致的索引状态;查看状态时会说明应答节点上没有构建记录。
  • 为什么做:知识库重建运维入口的后续修复,替多节点部署的运维和自动化脚本解决“构建在跑或已成功却被报失败”的问题。
  • 出错会怎样:只影响命令行的结论,不影响服务端构建本身;可直接撤回本改动恢复旧行为。
  • 要你做什么:无。

What changes

Design: the card's second option. The build record stays per node (no service change); the CLI falls back to the index state the store reports, which is the same on every node.

  • os knowledge rebuild reads index_status once before it starts the build, as the baseline. A progress read answered by a node without this build's record (no record, or a record with another startedAt) is no longer an exit 1. It reads the index state instead: when the baseline was not current (never built, new fingerprint, changed recipe, no recipe hash), the index turning current means a complete build recorded itself (adapters record the recipe hash only in completeBuild), and the command exits 0, saying the counts were not read.
  • When the baseline was already current, the index state cannot tell a running build from a finished one (a same-fingerprint rebuild opens no building generation in either adapter: knowledge-memory and knowledge-pgvector beginBuild), so the command keeps polling until a read reaches the building node, whose record decides.
  • Failure is reported only on the build's own recorded failure (failed / not-run) or after the new --timeout (seconds, default 600, counted as polls times --interval) of reads that reach no record of this build and do not see the index turn current. The timeout message says the build may still be running and points at os knowledge status; a read that reaches the record starts the timeout again, so a single-node build is never cut off.
  • os knowledge status labels the record as the answering node's, and when that node holds none says a build run on another node (or before a restart) is not shown, while the index state is the store's.
  • content/docs/deployment/cli.mdx Knowledge section and a patch changeset.

Measured before designing: index_status already returns index (state, due, detail, held) from the store and build (or null) from the answering node, so "no record on this node" (build: null) and "never built" (index.state: nothing) are separate fields; no service change was needed.

Tests

packages/cli/src/commands/knowledge/knowledge.test.ts, new describe "a poll that lands on a node without the build record": still running (polls alternate between a node without the record and the building node, exit 0), succeeded (index turns current, exit 0), an older record on the answering node read as no record, an index already current waits for the building node and reports its recorded failure, --timeout exits 1 with its statement, and the timeout restarts on a read of the record. Existing rebuild tests gained the baseline read.

Readings at 91e9a57
  • vitest run src/commands/knowledge/knowledge.test.ts: Test Files 1 passed, Tests 12 passed (lock VERDICT command-exit 0).
  • Ablation (rebuild.ts restored to the base c385d3b, tests kept): Tests 9 failed, 3 passed; restored, green.
  • pnpm --filter @objectstack/cli typecheck: VERDICT command-exit 0 (incl. check:test-typecheck OK).

Acceptance notes

  • The index_status answer carries no node identity, so os knowledge status can only say "the node that answered", never which node ran a build.
  • A failed build seen only through other nodes leaves the index due; the CLI cannot read that failure from the store and ends on --timeout.

Verification

Read first: packages/cli/src/commands/knowledge/rebuild.ts (the fallback branch after the record check), then the new tests.
Two-minute check: pnpm --filter @objectstack/cli exec vitest run --maxWorkers=2 src/commands/knowledge/knowledge.test.ts shows 12 passed.


Generated by Claude Code

…when a poll lands on another node

Claude-Session: https://claude.ai/code/session_01Utp6Cb4BAjgQ43tqy1DvVJ
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/cli, touching 7 documentable anchor(s).

2 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/knowledge-rag.mdx (via index_status (literal, a string literal in KnowledgeRebuild), os knowledge rebuild (command, read off packages/cli/src/commands/knowledge/rebuild.ts), os knowledge status (command, read off packages/cli/src/commands/knowledge/status.ts))
  • content/docs/deployment/cli.mdx (via index_status (literal, a string literal in KnowledgeRebuild), os knowledge rebuild (command, read off packages/cli/src/commands/knowledge/rebuild.ts), os knowledge status (command, read off packages/cli/src/commands/knowledge/status.ts))
What this run could not see
  • 1 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 40 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 0f6a1e518f3c4639b03f86a8c07d9d08d91bddb6 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 0161cdcd1edd20886aead2878a3b38a87b12bed1 — the merge of head 3b351697d10880a91dd4a6bafce636e6c68b116f into base 0f6a1e518f3c4639b03f86a8c07d9d08d91bddb6, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 0161cdcd1edd20886aead2878a3b38a87b12bed1 && git checkout 0161cdcd1edd20886aead2878a3b38a87b12bed1
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 0f6a1e518f3c4639b03f86a8c07d9d08d91bddb6 3b351697d10880a91dd4a6bafce636e6c68b116f && git checkout -B drift-repro 0f6a1e518f3c4639b03f86a8c07d9d08d91bddb6 && git merge --no-ff 3b351697d10880a91dd4a6bafce636e6c68b116f

node scripts/docs-audit/affected-docs.mjs --json 0f6a1e518f3c4639b03f86a8c07d9d08d91bddb6

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 0f6a1e518f3c4639b03f86a8c07d9d08d91bddb6 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract-review-claim: session_01Utp6CYtTDvfPQDzMbZnN5X · head 91e9a57 · 2026-11-26T14:18Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 91e9a57551df14ae7ba4be6d17e6696fc2c90338
Local-runs: none

Read: card #37466 (body, triage, first touch, claim, os-dev report), the PR #37578 body and Acceptance notes, the net diff against main (5 files, +248/−51, CLI and docs only), and the 55 check-runs on the head: 40 success, 15 skipped, 0 failure. Required contexts are green (Lint & Repo Gates, TypeScript Type Check, Test Core and shards 1–10, Build Core, Governed Surface Queue Guard, Check Changeset, PR-body guards).

① Derived judgments

  • Design. The PR takes the card's second option and makes no service change. That is right: index_status already returns index from the store and build (or null) from the answering node as separate fields (knowledge-build-actions.ts:151-152).
  • Public surface. os knowledge rebuild gains --timeout (seconds, default 600, min 1). It now also makes one index_status read before rebuild, and only with --wait. Its exit codes change: a poll answered by another node no longer exits 1 on its own. os knowledge status changes one output line. Nothing is removed or renamed, and no option is refused that was accepted before.
  • No false success: mostly holds. Success comes from the build's own done record, or from the index turning current after a baseline that was not current. A missing baseline state counts as current (rebuild.ts:109), so it never yields success. A same-fingerprint rebuild waits for the building node's record, which is correct because neither adapter opens a building generation for it. failed and not-run records still exit 1 (rebuild.ts:135). Two paths still give a false exit 0:
    • S2 (should-fix): baseline judged by state instead of due. indexWasCurrent is state === 'current', so any other state counts as a valid "was not current" baseline. unreadable is one of those states, and readIndexState returns it when the adapter read throws (knowledge-service.ts:890), so it can be transient. Take a transient error on the baseline read of a same-fingerprint rebuild: the next poll on another node reads current and exits 0 saying "a complete build has recorded itself", while this build is still running and may still fail. Separately, unknown, listed-*, not-built-here and a no-recipe-hash with no completeBuild never turn current, so for those the line "(waiting for it to turn current)" can only end on --timeout. Fix: take the fallback exit only when indexBefore?.due === true, which is exactly the never-built, new-fingerprint, recipe-changed and no-recipe-hash-with-completeBuild set the docblock names. Treat every other state like current. Add a test with an unreadable baseline followed by a current poll on another node, and assert no exit 0.
    • S3 (should-fix): the premise does not hold for the memory adapter. The code, docs and status line all say the store's index state is "the same on every node". That is true for pgvector. It is false for the default memory adapter, whose index is a per-process Map (knowledge-memory/src/index.ts:91). Behind a load balancer the baseline can come from a node whose memory index is due (restarted, boot build not yet done, or buildAtBoot: false). A later poll can then land on a node whose own memory index is current, and the command exits 0 while the build on the third node runs. Fix: do not take the index-current exit when the source's adapter is memory (the view carries it). In cli.mdx (the status and rebuild paragraphs) and the status line, say the index is the same on every node only when the adapter's store is shared.
  • Poll loop. There is no tight spin: every pass waits --interval seconds (min 1) before its read. The no-record wait is bounded by --timeout and resets only on a read of this build's record, so a single-node build is never cut off. A build that stays running on its node is followed for as long as it runs, as before. Every read failure still exits 1 at once, as before.
    • N1 (nit): --timeout counts reads times --interval, not wall-clock time, and runKnowledgeAction (not in the diff) sets no request timeout. A request that hangs is therefore not bounded by --timeout. The flag text and the docs describe this accurately, so it is a note, not a defect.
  • Stale or older records. A record with another startedAt is read as no record (tested). startedAt is always present on a real server, because rebuildSource sets the record synchronously (knowledge-service.ts:924-931). The startedAt === undefined branch only covers an older server.
  • Tests: real controls. The 6 new cases cover each branch with a negative control. A current baseline never exits 0 from the index; the build's own recorded failure still exits 1; --timeout 4 against --interval 2 exits on exactly the 2nd unseen read; and the reset case turns red if the reset is removed. The ablation result (9 of 12 red when rebuild.ts is put back to the base) explains as follows:
    • The 3 that stay green: the two os knowledge status cases, because the ablation restored only rebuild.ts and status.ts kept the PR's text. Also the --no-wait case: the new baseline read is gated on flags.wait (rebuild.ts:86), so its single-request sequence is the same on base.
    • Of the 9 red, 3 are older rebuild cases ("follows it to its end", "did not finish", "refusal text"). They turn red only because the fixture gained a baseline response that base hands to rebuild. That is a fixture shift, not behaviour, so the behavioural evidence is the 6 new cases. That is enough.
    • The status text change has no ablation reading, but its assertion pins the new line ("none recorded there"), which the base line would fail.
    • None of the 12 covers an unreadable baseline (S2).

② Semver level

③ Boundary flags

  • open_questions: empty. Nothing to answer.
  • Accepted limit 1: no node identity in index_status. Acceptable, and no card needed. It limits labelling only: status now says "the node that answered", which is true, and it says when that node holds no record. Adding a node id to the answer is a service change outside this card. A shared build record (the card's first option) would remove the limit.
  • Accepted limit 2: a failed build seen only through other nodes ends on --timeout. Acceptable, and no card needed. Exit 1 is the right code for a failure; it only comes late, and the message honestly says the build may still be running. The same timeout also catches a successful same-fingerprint rebuild whose reads never reach the building node. At the default that needs about 300 reads in a row to miss one node, which is negligible under round-robin. File the shared build record only if an operator reports the wait.
  • Dev flags: the two out_of_scope_findings are these two limits, answered above. dogfood_battery n/a is right: no ! and no narrowing arm. security_findings: none, agreed; the admin gate is unchanged and server-side.
  • SQL push-down: not applicable. The diff is CLI and docs only, with no data access, id materialisation or join.
  • Owed before merge: S1 (two declaration lines), S2 (a one-line predicate and one test), S3 (an adapter check or a docs qualification). N1 is optional.

Implemented-by: claude/issue-37466-knowledge-cli-lb
Reviewed-by: session_01Utp6CYtTDvfPQDzMbZnN5X

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#5 · os-bill · session_01Utp6CYtTDvfPQDzMbZnN5X

席位核对

Head-sha: 91e9a57551df14ae7ba4be6d17e6696fc2c90338
REWORK — L1, seat repo:objectstack#5

  1. Shape: draft against main. CLI and docs only. Not governed, not security-touching.
  2. Premise: the --timeout option and the fallback that reads the shared index state are sound. Both accepted limits (no node identity in index_status; a failed build seen only through other nodes ends on --timeout with exit 1) stand with no card.
  3. Gates: contract record 7194806473 (TIER_DEFAULT) reads PASS with three should-fix findings owed before landing. CI on this head: 40 success, 15 skipped, 0 failed.
  4. Owed before landing (ids from the record):
  5. Accepted deviations: N1 (--timeout counts polls times --interval; the PR already says so).
  6. Landing terms: after the delta the seat re-reviews with the same reviewer. Then the area lands it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

service-knowledge: os knowledge rebuild and status give the right answer behind a load balancer

2 participants